import React, { Component, Fragment } from 'react';
import { connect } from 'dva'
import BaseTable from './baseTable'
import { Space, Popconfirm, Upload, Descriptions, Modal } from 'antd'
import constant from '../../constant/constant'

class UserTable extends BaseTable {
    constructor(props) {
        super(props),
            this.state = {
                column: [
                    { title: "用户账号", dataIndex: "userName", key: "userName", ...this.getColumnSearchProps("userName") },
                    {
                        title: "用户类型", dataIndex: "userType", key: "userType",
                        filters: [
                            { text: "技术供应商", value: "技术供应商" },
                            { text: "机构", value: "机构" },
                        ],
                        onFilter: (value, record) => record.userType.indexOf(value) === 0
                    },
                    {
                        title: "操作", dataIndex: "operation", key: "operation",
                        render: (text, record, index) => {
                            return(
                                <Space>
                                    <a onClick={()=>{this.changePassword(record.id)}}>重置密码</a>
                                    <a>删除</a>
                                </Space>
                            )
                        }
                    }
                ]
            }
    }

    componentDidMount(){
        this.props.dispatch({
            type:"backstageManagement/getUserTableData"
        })
    }

    changePassword = id => {
        this.props.dispatch({
            type:"backstageManagement/changePasswordById",
            data:{
                id:id,
                password:"123456"
            }
        })
    }

    render() {
        return super.render(this.state.column, this.props.dataSource,{pageSize:12})
    }
}

const mapStateToProps = state => {
    let dataSource = state.backstageManagement.userList
    return {
        dataSource
    }
}

export default connect(mapStateToProps)(UserTable)